package com.demolist.demo.list.v1;

import javax.xml.ws.soap.Addressing;
import java.util.Arrays;

public class InsertArray {
    public static void main(String[] args) {
        int index = 0;
        String value = "555555";
        String value2 = "11111";
        String[] array = new String[]{"11111","222222","33333","4444444"};
        System.out.println(Arrays.toString(array));

        String[] addarr =add(array,value);
        System.out.println(Arrays.toString(addarr));

        String[] rearr =remove(array,value2);
        System.out.println(Arrays.toString(rearr));

    }


    public static String[] add(String[] arrays,String data){
        int size=arrays.length+1;
        String[] addarr=new String[size];
        addarr = Arrays.copyOf(arrays,size);
        addarr[arrays.length] = data;
        return addarr;
    }

    public static String[] remove(String[] arrays,String data){
        int size=arrays.length;
        int position = 0;
        String[] addarr=new String[size];
        for (int i = 0; i <arrays.length ; i++) {
            if (data.equals(arrays[i])){
                position = i;
//                System.out.println("arrays["+i+"]--->"+arrays[i]);
            }else {
                addarr[i] = arrays[i];
            }
        }
        System.arraycopy(addarr,position+1,addarr,position,size-position-1);
        addarr = Arrays.copyOf(addarr,size-1);
        return addarr;
    }

}
